package com.dapeis.web.wx.wx.router;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dapeis.web.wx.wx.demo.DemoGuessNumberHandler;
import com.dapeis.web.wx.wx.demo.DemoTextHandler;
import com.dapeis.web.wx.wx.handler.WxEventCustomCmdHandler;
import com.dapeis.web.wx.wx.handler.WxEventCustomerServiceHandler;
import com.dapeis.web.wx.wx.handler.WxEventMyOrderHandler;
import com.dapeis.web.wx.wx.handler.WxEventSubscribeHandler;
import com.dapeis.web.wx.wx.handler.WxEventUnSubscribeHandler;
import com.dapeis.web.wx.wx.handler.WxLogHandler;

/**
 * 
 * Title:StylistWxMpMessageRouter.java StylistWxMpMessageRouter
 * Description:
 * @author yuanyong
 * @date 2017年4月27日 上午9:33:16 
 * Email: hzyuanyong@126.com
 *
 */
@Component
public class StylistWxMpMessageRouter extends WxMpMessageRouter {
	
	@Resource WxLogHandler mWXLogHandler;
	@Resource WxEventCustomCmdHandler mWxEventCustomCmdHandler;
	@Resource WxEventSubscribeHandler mWXEventSubscribeHandler;
	@Resource WxEventUnSubscribeHandler mWXEventUnSubscribeHandler;
	@Resource WxEventMyOrderHandler mWXEventMyOrderHandler;
	@Resource WxEventCustomerServiceHandler mWXEventCustomerServiceHandler;
	@Resource DemoGuessNumberHandler guessNumberHandler;
	@Resource DemoTextHandler textHandler;
	@Autowired
	public StylistWxMpMessageRouter(WxMpService wxMpService) {
		super(wxMpService);
	}

	@PostConstruct
	public void registHandler() {
	    this
	          .rule().handler(mWXLogHandler).next()
	          .rule().msgType(WxConsts.XML_MSG_TEXT).handler(mWxEventCustomCmdHandler).next()
	          .rule().async(false).event(WxConsts.EVT_CLICK).eventKey("my_order").handler(mWXEventMyOrderHandler).end()
	          .rule().async(false).event(WxConsts.EVT_CLICK).eventKey("customer_service").handler(mWXEventCustomerServiceHandler).end()
	          .rule().async(false).event(WxConsts.EVT_SUBSCRIBE).handler(mWXEventSubscribeHandler).end()
	          .rule().async(false).event(WxConsts.EVT_UNSUBSCRIBE).handler(mWXEventUnSubscribeHandler).end()
	          .rule().msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler).handler(guessNumberHandler).end();
	}
}
